<?php

namespace app\models;

use think\Db;
use think\Model;

class UserConfig extends Model
{

    public static function getlevel($user)
    {
        $level = (new UserConfig())->order('level desc')->where('pnumber', '<=', $user['tmoney'])->value('level') ?? 0;
        if ($level >= 1 && $user['level'] != $level && $user['level'] > 0) {
            User::where('id', $user['id'])->update(['level' => $level]);
            $user['level'] = $level;
        }
    }
}
